import React, { useEffect, useState } from "react";
import Actions from "../qiankun/actions";

import Sidebar from "../components/Sidebar";
import Content from "../components/Content";

function Home() {
  const [activeMenu, setActiveMenu] = useState("考勤日报");
  const [username, setUsername] = useState('');
    
  useEffect(() => {
      // 注册回调，获取全局状态
      const unsubscribe = Actions.onGlobalStateChange((state) => {
          if (state && state.username) {
              setUsername(state.username);
          }
      }, true);
      
      // 组件卸载时清理订阅
      return () => {
          if (typeof unsubscribe === 'function') {
              unsubscribe();
          }
      };
  }, []); // 空依赖数组，确保只在组件挂载时执行一次
  const clickBtn=()=>{
      Actions.setGlobalState({username:'lisi'})
  }

  return (
    <div style={{ display: "flex",  background: "#fff" }}>
      <Sidebar activeMenu={activeMenu} setActiveMenu={setActiveMenu} />
      <div style={{ flex: 1, padding: 24 }}>
        <Content activeMenu={activeMenu} />
      </div>
      {/* <button onClick={clickBtn}>修改数据</button> */}
      {/* <h1>{username}</h1> */}
    </div>
  );
}
export default Home;

